<template>
  <el-dialog :visible.sync="visible" :title="!dataForm.id ? $t('add') : $t('update')" :close-on-click-modal="false" :close-on-press-escape="false">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmitHandle()" :label-width="$i18n.locale === 'en-US' ? '120px' : '80px'">
          <el-form-item label="订单编号" prop="orderNo">
          <el-input v-model="dataForm.orderNo" placeholder="订单编号"></el-input>
      </el-form-item>
          <el-form-item label="乘机人编号 必须" prop="psgNo">
          <el-input v-model="dataForm.psgNo" placeholder="乘机人编号 必须"></el-input>
      </el-form-item>
          <el-form-item label="乘客姓名，英文名字或拼音需在姓与名之间加上“/”，如“zhou/jielun” 必须" prop="psgName">
          <el-input v-model="dataForm.psgName" placeholder="乘客姓名，英文名字或拼音需在姓与名之间加上“/”，如“zhou/jielun” 必须"></el-input>
      </el-form-item>
          <el-form-item label="乘机人类型 1成人 2儿童 3婴儿 必须" prop="psgType">
          <el-input v-model="dataForm.psgType" placeholder="乘机人类型 1成人 2儿童 3婴儿 必须"></el-input>
      </el-form-item>
          <el-form-item label="证件类型，1-身份证 2-护照5-台胞证 7-回乡证 8-军官证 9-其他，10-外国人永久居留证，14-港澳居民居住证，15-台湾居民居住证 必须" prop="cardType">
          <el-input v-model="dataForm.cardType" placeholder="证件类型，1-身份证 2-护照5-台胞证 7-回乡证 8-军官证 9-其他，10-外国人永久居留证，14-港澳居民居住证，15-台湾居民居住证 必须"></el-input>
      </el-form-item>
          <el-form-item label="证件号码 必须" prop="cardNo">
          <el-input v-model="dataForm.cardNo" placeholder="证件号码 必须"></el-input>
      </el-form-item>
          <el-form-item label="手机号码 必须" prop="mobile">
          <el-input v-model="dataForm.mobile" placeholder="手机号码 必须"></el-input>
      </el-form-item>
          <el-form-item label="出生日期 必须" prop="birthday">
          <el-input v-model="dataForm.birthday" placeholder="出生日期 必须"></el-input>
      </el-form-item>
          <el-form-item label="账单价 必须" prop="personPrice">
          <el-input v-model="dataForm.personPrice" placeholder="账单价 必须"></el-input>
      </el-form-item>
          <el-form-item label="机建 必须" prop="personAirportTax">
          <el-input v-model="dataForm.personAirportTax" placeholder="机建 必须"></el-input>
      </el-form-item>
          <el-form-item label="燃油" prop="personTaxPrice">
          <el-input v-model="dataForm.personTaxPrice" placeholder="燃油"></el-input>
      </el-form-item>
          <el-form-item label="性别，1-男，2-女" prop="gender">
          <el-input v-model="dataForm.gender" placeholder="性别，1-男，2-女"></el-input>
      </el-form-item>
          <el-form-item label="国籍，国家二字码，除身份证、港澳居民居住证、台湾居民居住证外其他证件类型必传" prop="countryCode">
          <el-input v-model="dataForm.countryCode" placeholder="国籍，国家二字码，除身份证、港澳居民居住证、台湾居民居住证外其他证件类型必传"></el-input>
      </el-form-item>
          <el-form-item label="国籍名称，除身份证、港澳居民居住证、台湾居民居住证外其他证件类型必传" prop="countryName">
          <el-input v-model="dataForm.countryName" placeholder="国籍名称，除身份证、港澳居民居住证、台湾居民居住证外其他证件类型必传"></el-input>
      </el-form-item>
          <el-form-item label="发证国家二字码，，除身份证、港澳居民居住证、台湾居民居住证外其他证件类型必传" prop="issCountryCode">
          <el-input v-model="dataForm.issCountryCode" placeholder="发证国家二字码，，除身份证、港澳居民居住证、台湾居民居住证外其他证件类型必传"></el-input>
      </el-form-item>
          <el-form-item label="发证国家名称，，除身份证、港澳居民居住证、台湾居民居住证外其他证件类型必传" prop="issCountryName">
          <el-input v-model="dataForm.issCountryName" placeholder="发证国家名称，，除身份证、港澳居民居住证、台湾居民居住证外其他证件类型必传"></el-input>
      </el-form-item>
          <el-form-item label="证件有效期，格式为yyyy-MM-dd，，除身份证、港澳居民居住证、台湾居民居住证外其他证件类型必传" prop="cardExpireDate">
          <el-input v-model="dataForm.cardExpireDate" placeholder="证件有效期，格式为yyyy-MM-dd，，除身份证、港澳居民居住证、台湾居民居住证外其他证件类型必传"></el-input>
      </el-form-item>
          <el-form-item label="应收金额" prop="personSalePrice">
          <el-input v-model="dataForm.personSalePrice" placeholder="应收金额"></el-input>
      </el-form-item>
          <el-form-item label="技术服务费" prop="personSaleServicePrice">
          <el-input v-model="dataForm.personSaleServicePrice" placeholder="技术服务费"></el-input>
      </el-form-item>
          <el-form-item label="实收金额" prop="personSupRealAmount">
          <el-input v-model="dataForm.personSupRealAmount" placeholder="实收金额"></el-input>
      </el-form-item>
          <el-form-item label="返点" prop="commisionPoint">
          <el-input v-model="dataForm.commisionPoint" placeholder="返点"></el-input>
      </el-form-item>
          <el-form-item label="定额" prop="commisionMoney">
          <el-input v-model="dataForm.commisionMoney" placeholder="定额"></el-input>
      </el-form-item>
              <el-form-item label="更新人" prop="updator">
          <el-input v-model="dataForm.updator" placeholder="更新人"></el-input>
      </el-form-item>
          <el-form-item label="更新时间" prop="updateDate">
          <el-input v-model="dataForm.updateDate" placeholder="更新时间"></el-input>
      </el-form-item>
      </el-form>
    <template slot="footer">
      <el-button @click="visible = false">{{ $t('cancel') }}</el-button>
      <el-button type="primary" @click="dataFormSubmitHandle()">{{ $t('confirm') }}</el-button>
    </template>
  </el-dialog>
</template>

<script>
import debounce from 'lodash/debounce'
export default {
  data () {
    return {
      visible: false,
      dataForm: {
        id: '',
        orderNo: '',
        psgNo: '',
        psgName: '',
        psgType: '',
        cardType: '',
        cardNo: '',
        mobile: '',
        birthday: '',
        personPrice: '',
        personAirportTax: '',
        personTaxPrice: '',
        gender: '',
        countryCode: '',
        countryName: '',
        issCountryCode: '',
        issCountryName: '',
        cardExpireDate: '',
        personSalePrice: '',
        personSaleServicePrice: '',
        personSupRealAmount: '',
        commisionPoint: '',
        commisionMoney: '',
        creator: '',
        createDate: '',
        updator: '',
        updateDate: ''
      }
    }
  },
  computed: {
    dataRule () {
      return {
        orderNo: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        psgNo: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        psgName: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        psgType: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        cardType: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        cardNo: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        mobile: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        birthday: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        personPrice: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        personAirportTax: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        personTaxPrice: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        gender: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        countryCode: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        countryName: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        issCountryCode: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        issCountryName: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        cardExpireDate: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        personSalePrice: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        personSaleServicePrice: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        personSupRealAmount: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        commisionPoint: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        commisionMoney: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        updator: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        updateDate: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    init () {
      this.visible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()
        if (this.dataForm.id) {
          this.getInfo()
        }
      })
    },
    // 获取信息
    getInfo () {
      this.$http.get(`/flight/orderpassenger/${this.dataForm.id}`).then(({ data: res }) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        this.dataForm = {
          ...this.dataForm,
          ...res.data
        }
      }).catch(() => {})
    },
    // 表单提交
    dataFormSubmitHandle: debounce(function () {
      this.$refs['dataForm'].validate((valid) => {
        if (!valid) {
          return false
        }
        this.$http[!this.dataForm.id ? 'post' : 'put']('/flight/orderpassenger/', this.dataForm).then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg)
          }
          this.$message({
            message: this.$t('prompt.success'),
            type: 'success',
            duration: 500,
            onClose: () => {
              this.visible = false
              this.$emit('refreshDataList')
            }
          })
        }).catch(() => {})
      })
    }, 1000, { 'leading': true, 'trailing': false })
  }
}
</script>
